package com.ruoyi.local.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.local.mapper.LayerListMapper;
import com.ruoyi.local.domain.LayerList;
import com.ruoyi.local.service.ILayerListService;
import com.ruoyi.common.core.text.Convert;

/**
 * 图层管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-12-23
 */
@Service
public class LayerListServiceImpl implements ILayerListService 
{
    @Autowired
    private LayerListMapper layerListMapper;

    /**
     * 查询图层管理
     * 
     * @param layerId 图层管理ID
     * @return 图层管理
     */
    @Override
    public LayerList selectLayerListById(Long layerId)
    {
        return layerListMapper.selectLayerListById(layerId);
    }

    /**
     * 查询图层管理列表
     * 
     * @param layerList 图层管理
     * @return 图层管理
     */
    @Override
    public List<LayerList> selectLayerListList(LayerList layerList)
    {
        return layerListMapper.selectLayerListList(layerList);
    }

    /**
     * 新增图层管理
     * 
     * @param layerList 图层管理
     * @return 结果
     */
    @Override
    public int insertLayerList(LayerList layerList)
    {
        layerList.setCreateTime(DateUtils.getNowDate());
        return layerListMapper.insertLayerList(layerList);
    }

    /**
     * 修改图层管理
     * 
     * @param layerList 图层管理
     * @return 结果
     */
    @Override
    public int updateLayerList(LayerList layerList)
    {
        layerList.setUpdateTime(DateUtils.getNowDate());
        return layerListMapper.updateLayerList(layerList);
    }

    /**
     * 删除图层管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLayerListByIds(String ids)
    {
        return layerListMapper.deleteLayerListByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除图层管理信息
     * 
     * @param layerId 图层管理ID
     * @return 结果
     */
    @Override
    public int deleteLayerListById(Long layerId)
    {
        return layerListMapper.deleteLayerListById(layerId);
    }

    /**
     * 查询图层管理树列表
     * 
     * @return 所有图层管理信息
     */
    @Override
    public List<Ztree> selectLayerListTree()
    {
        List<LayerList> layerListList = layerListMapper.selectLayerListList(new LayerList());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (LayerList layerList : layerListList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(layerList.getLayerId());
            ztree.setpId(layerList.getParentId());
            ztree.setName(layerList.getLayerName());
            ztree.setTitle(layerList.getLayerName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
